package io.jee.medusa.utils;

import java.util.Random;

public class RandomUtils {
	
	public final static String ALL = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	public final static String NUMBER = "0123456789";
	public final static String UPPERCASS_AND_NUMBER = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	public final static String LOWERCASS = "abcdefghijklmnopqrstuvwxyz";
	
	public static String getRandom(String base, int length){
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString(); 
	}

	public static String getAll(int length) {
		return getRandom(ALL, length);
	}
	
	public static String getNumber(int length) { // length表示生成字符串的长度
		return getRandom(NUMBER, length);
	}
	
	public static String getNumberFristNotZero(int length){
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		boolean frist = true;
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(NUMBER.length());
			char f = NUMBER.charAt(number);
			if(frist){
				while(f == '0'){
					f = NUMBER.charAt(number);
				}
				frist = false;
			}
			sb.append(f);
		}
		return sb.toString(); 
	}

}
